package com.guigu.liuzhireng.service.impl;

import com.guigu.liuzhireng.mapper.AuthorizationMapper;
import com.guigu.liuzhireng.mapper.RoleauthorizationMapper;
import com.guigu.liuzhireng.pojo.Authorization;
import com.guigu.liuzhireng.pojo.Roleauthorization;
import com.guigu.liuzhireng.service.RoleauthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleauthorizationServiceImpl implements RoleauthorizationService {
    @Autowired
    RoleauthorizationMapper roleauthorizationMapper;
    @Autowired
    AuthorizationMapper authorizationMapper;

    @Override
    public List<Authorization> RoleauthorizationAll(Integer roleid) {
        List<Authorization> roles = authorizationMapper.Auths(new Authorization());
        List<Roleauthorization> list = roleauthorizationMapper.RoleauthorizationAll(roleid);

        for (Authorization r : roles) {
            for (Roleauthorization ar : list) {
                if (ar.getAuid().equals(r.getAuid())){
                    r.setTf(true);
                }
            }
        }
        return roles;
    }

    @Override
    public int DelAdd(List<Roleauthorization> list, Integer roleid) {
        int deletes = roleauthorizationMapper.deletes(roleid);
        int inserts = roleauthorizationMapper.inserts(list);
        return deletes+inserts;
    }
}
